Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Redundant RwLock and Arc; Removed parking_lot Dependency #75

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

bushrat011899
Copy link
Contributor

Objective

The RollbackTypeRegistry contains a TypeRegistry, which itself is a thin wrapper around TypeRegistryInternal, but through an Arc<RwLock<...>>. This indirection adds overhead to every interaction with the rollback type registry for no particular reason and should be removed. As a bonus, removing it would remove the need for the parking_lot dependency (still in the graph because of Bevy)

Solution

Stored TypeRegistryInternal inside the RollbackTypeRegistry instead and removed lock acquisition code.

`TypeRegistryInternal` only needs to be available in an `Arc<RwLock<...>>` for Bevy scenes loading/unloading, which I don't believe is used at all for this plugin.
@johanhelsing
Copy link
Collaborator

Is this a performance problem in practice (root of all-evil and all that)?

Doesn't the Internal suffix mean it's considered private Bevy API?

@bushrat011899
Copy link
Contributor Author

Is this a performance problem in practice (root of all-evil and all that)?

To my knowledge, no, and I'd be surprised if any benchmark could even reliably measure any difference. My goal is just to simplify that part, since the Arc and RwLock don't provide any benefits in this case.

Doesn't the Internal suffix mean it's considered private Bevy API?

Not in this case. The reason for TypeRegistry and TypeRegistryInternal is that because of how scenes and assets are loaded, the TypeRegistry needs to be accessed in a way that's only possible through Arc<RwLock<...>>. For bevy_ggrs, that requirement does not exist. If you look at the definition for TypeRegistry in Bevy, you'll see a comment explaining the eventual desire to remove it entirely in favour of TypeRegistryInternal. You can even see it through the type names, as TypeRegistryInternal is actually named TypeRegistry, while TypeRegistry is named TypeRegistryArc.

Copy link
Owner

@gschup gschup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why using the TypeWriterInternal is better here, good catch. When I wrote this, I think I just took the TypeWriter usage from some bevy code.

Since bevy is going to change a lot anyway, I think it is fine to use this as is.

Copy link
Collaborator

@johanhelsing johanhelsing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this case. The reason for TypeRegistry and TypeRegistryInternal is that because of how scenes and assets are loaded, the TypeRegistry needs to be accessed in a way that's only possible through Arc<RwLock<...>>. For bevy_ggrs, that requirement does not exist. If you look at the definition for TypeRegistry in Bevy, you'll see a comment explaining the eventual desire to remove it entirely in favour of TypeRegistryInternal. You can even see it through the type names, as TypeRegistryInternal is actually named TypeRegistry, while TypeRegistry is named TypeRegistryArc.

Excellent. In that case, I have no objections. And nice with simpler code :)

@gschup gschup merged commit a6139d2 into gschup:main Oct 19, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants